package com.poker;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class App {

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }

    /**
     * 参数：1，2两个人受伤的五张扑克
     * 假设J=11，Q=12，K=13，A=14
     */
    @RequestMapping(value = "/test", method = RequestMethod.POST)
    @ResponseBody
    public String test(@RequestBody PokerParamVo paramVo) {
        if (null == paramVo || null == paramVo.getGamblerOne()
            || null == paramVo.getGamblerTwo()
            || CollectionUtils.isEmpty(paramVo.getGamblerOne().getPokers())
            || CollectionUtils.isEmpty(paramVo.getGamblerTwo().getPokers())
            || 5 != paramVo.getGamblerOne().getPokers().size()
            || 5 != paramVo.getGamblerTwo().getPokers().size()) {
            return "poker is not enough";
        }
        for (Integer poker : paramVo.getGamblerOne().getPokers()) {
            if (poker > 14 || poker < 2) {
                return "Gamber one has a card which is not a poker!";
            }
        }
        for (Integer poker : paramVo.getGamblerTwo().getPokers()) {
            if (poker > 14 || poker < 2) {
                return "Gamber two has a card which is not a poker!";
            }
        }
        //比较大小，1为第一个人大，0为和牌，-1为第二个人大
        int i = paramVo.getGamblerOne().compareTo(paramVo.getGamblerTwo());
        if (i == 1) {
            return "winner is:" + paramVo.getGamblerOne().getName();
        } else if (i == 0) {
            return "peace!!!";
        } else {
            return "winner is:" + paramVo.getGamblerTwo().getName();
        }
    }
}
